import strformat
import math
import strutils

proc calculateMusicTime(bars: int,bpm: float,numerator: int, denominator: int): string =
    # 计算总拍数 = 小节数 * 每小节的拍数
    let totalBeats: int = bars * numerator
    
    # 计算总秒数 = 总拍数 * (60秒 / BPM)
    var totalSeconds: float = float(totalBeats) * 60.0 / bpm
    
    # 分解为分钟和秒
    var minutes = (totalSeconds.int) / 60
    var seconds = math.round(totalSeconds - float(minutes) * 60).int
    
    # 处理秒数进位（如62秒转为1分02秒）
    if seconds >= 60:
        minutes += float(seconds div 60)
        seconds = seconds mod 60
    
    # 格式化输出为MM:SS（补零）
    var a = "minutes: " & $minutes & " seconds: " & $seconds
    return a

echo "请输入小节"
var bars = stdin.readLine()
echo "请输入BPM"
var bpm = stdin.readLine()
echo "请输入拍号分子"
var numerator = stdin.readLine()
echo "请输入拍号分母"
var denominator = stdin.readLine()
echo calculateMusicTime(bars.parseInt(),bpm.parseFloat(),numerator.parseInt(),denominator.parseInt());